import 'package:flutter/material.dart';
import 'package:inmotion_pro/l10n/local.dart';
import 'package:inmotion_pro/pages/mine/view/calendar_icon.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

// 订单状态卡片（可自定义宽度）
class OrderStatusCardFlexible extends StatelessWidget {
  final String orderMonth;
  final String orderDay;
  final String statusTitle;
  final String orderNumber;
  final VoidCallback onTap;
  final Color? backgroundColor;
  final Color? themeColor;
  final double borderRadius;
  final double calendarWidth;

  const OrderStatusCardFlexible({
    super.key,
    required this.orderMonth,
    required this.orderDay,
    required this.statusTitle,
    required this.orderNumber,
    required this.calendarWidth,
    required this.onTap,
    this.backgroundColor,
    this.themeColor,
    this.borderRadius = 12,
  });

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.only(
          left: CONTENT_MARGIN, right: CONTENT_MARGIN, bottom: CONTENT_MARGIN),
      child: ClipRRect(
        borderRadius: BorderRadius.circular(borderRadius),
        child: Container(
          color: GrayColor.gray1,
          child: Padding(
            padding: EdgeInsets.all(CONTENT_MARGIN),
            child: Row(
              children: [
                CalendarIcon(
                  month: orderMonth,
                  day: orderDay,
                  width: calendarWidth,
                ),
                SizedBox(
                  width: CONTENT_MARGIN / 2,
                ),
                _buildOrderInfoSection(context),
              ],
            ),
          ),
        ),
      ),
    );
  }

  Widget _buildOrderInfoSection(BuildContext context) {
    return Expanded(
      child: InkWell(
        onTap: onTap,
        child: Column(
          children: [
            // 状态行
            _buildInfoRow(
              title: local.order_status,
              value: statusTitle,
              valueColor: LxColors.theme,
              showArrow: true,
            ),
            const SizedBox(height: 10),
            // 订单号行
            _buildInfoRow(
              title: local.order_number,
              value: orderNumber,
              valueColor: Colors.white,
              showArrow: false,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildInfoRow({
    required String title,
    required String value,
    required Color valueColor,
    required bool showArrow,
  }) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        LxText(
          title,
          color: Colors.white.withOpacity(0.6),
          fontWeightEnum: LxFontWeightEnum.bodyMedium,
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.end,
          children: [
            Container(
              constraints: BoxConstraints(maxWidth: screenWidth / 2),
              child: LxText(
                value,
                color: valueColor,
                fontWeightEnum: LxFontWeightEnum.bodyMedium,
                maxLines: 0,
              ),
            ),
            if (showArrow) ...[
              const SizedBox(width: 5),
              Icon(
                Icons.chevron_right,
                color: Colors.white.withOpacity(0.3),
              ),
            ],
          ],
        ),
      ],
    );
  }
}
